<?php

namespace App\Model\Steam;
use Illuminate\Database\Eloquent\Model;

class SteamGamePicture extends Model
{
    protected $table = 'steam_game_picture';
    public $timestamps = false;

    /**
     * 为“商品列表”填写“图片列表”项
     * @param $data
     */
    public static function getListPicture($data){
        $gameIds = [];
        foreach ($data as $key => $item) {
            $gameIds[] = $item['id'];
            $data[$key]['picture'] = [];
        }
        $pictureList = self::select('id', 'game_id', 'img_name', 'img_original', 'img_url')
            ->whereIn('game_id', $gameIds)
            ->orderBy('game_id')
            ->get();
        if($pictureList) {
            $pictureList = $pictureList->toArray();
            $pictureData = [];
            foreach ($pictureList as $k => $v) {
                $pictureData[$v['game_id']][] = $v;
            }
            foreach ($data as $key => $item) {
                if(isset($pictureData[$item['id']])) {
                    $data[$key]['picture'] = $pictureData[$item['id']];
                }
            }
        }
        return $data;
    }
}